package com.ruoyi.project.module.cloudPe.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.constant.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.module.cloudPe.domain.CloudPe;
import com.ruoyi.project.module.cloudPe.service.ICloudPeService;

/**
 * PE管理 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-07-23
 */
@Controller
@RequestMapping("/module/cloudPe")
public class CloudPeController extends BaseController
{
    private String prefix = "module/cloudPe";
	
	@Autowired
	private ICloudPeService cloudPeService;
	
	@RequiresPermissions("module:cloudPe:view")
	@GetMapping()
	public String cloudPe()
	{
	    return prefix + "/cloudPe";
	}
	
	/**
	 * 查询PE管理列表
	 */
	@RequiresPermissions("module:cloudPe:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(CloudPe cloudPe)
	{
		startPage();
        List<CloudPe> list = cloudPeService.selectCloudPeList(cloudPe);
		return getDataTable(list);
	}
	
	
	/**
	 * 查询PE管理列表
	 */
	@RequiresPermissions("module:cloudPe:list")
	@PostMapping("/selectCloudPeListbyCPe")
	@ResponseBody
	public TableDataInfo list(Integer cpeId)
	{
		startPage();
        List<CloudPe> list = cloudPeService.selectCloudPeListbyCPe(cpeId);
		return getDataTable(list);
	}
	
	/**
	 * 新增PE管理
	 */
	@RequiresPermissions("module:cloudPe:add")
	@Log(title = "PE管理", action = BusinessType.INSERT)
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}

	/**
	 * 修改PE管理
	 */
	@RequiresPermissions("module:cloudPe:edit")
	@Log(title = "PE管理", action = BusinessType.UPDATE)
	@GetMapping("/edit/{peId}")
	public String edit(@PathVariable("peId") Integer peId, Model model)
	{
		CloudPe cloudPe = cloudPeService.selectCloudPeById(peId);
		model.addAttribute("cloudPe", cloudPe);
	    return prefix + "/edit";
	}
	
	/**
	 * 保存PE管理
	 */
	@RequiresPermissions("module:cloudPe:save")
	@Log(title = "PE管理", action = BusinessType.SAVE)
	@PostMapping("/save")
	@ResponseBody
	public AjaxResult save(CloudPe cloudPe)
	{
		if (cloudPeService.saveCloudPe(cloudPe) > 0)
		{
			return success();
		}
		return error();
	}
	
	/**
	 * 删除PE管理
	 */
	@RequiresPermissions("module:cloudPe:remove")
	@Log(title = "PE管理", action = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{
		int rows = cloudPeService.deleteCloudPeByIds(ids);
		if (rows > 0)
        {
            return success();
        }
        return error();
	}
	
}
